package com.cvte.boe.media.views.settingpage;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListView;

import com.cvte.boe.media.R;
import com.cvte.boe.media.adapter.AudioFileAdapter;
import com.cvte.boe.media.model.LocalMediaInfo;
import com.cvte.boe.media.player.VideoPlayer;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wuguitong on 2018/5/17.
 */
public class PageAudioPlayerFileList extends LinearLayout {
    private Context mContext;
    private ListView mFileListView;
    private AudioFileAdapter mAudioFileAdapter;
    private List<LocalMediaInfo> mMediaInfoList;
    private OnAudioPageChangeListener mOnAudioPageChangeListener;
    public interface OnAudioPageChangeListener{
        void OnAudioFileChange(String filePath,int pos);
    }

    public PageAudioPlayerFileList(Context context,List<LocalMediaInfo> list) {
        this(context,null,list);
    }

    public PageAudioPlayerFileList(Context context, AttributeSet attrs,List<LocalMediaInfo> list) {
        this(context, null,0,list);
    }

    public PageAudioPlayerFileList(Context context, AttributeSet attrs, int defStyleAttr, List<LocalMediaInfo> list) {
        super(context, attrs, defStyleAttr);
        this.mContext = context;
        mMediaInfoList = new ArrayList<LocalMediaInfo>();
        mMediaInfoList.clear();
        mMediaInfoList.addAll(list);
        inflate(mContext, R.layout.page_music_player_filelist,this);
        mFileListView = (ListView)findViewById(R.id.lv_page_music_filelist);
        mAudioFileAdapter = new AudioFileAdapter(mContext,mMediaInfoList);
        mFileListView.setAdapter(mAudioFileAdapter);
        mFileListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                if(mOnAudioPageChangeListener != null){
                    mOnAudioPageChangeListener.OnAudioFileChange(mMediaInfoList.get(i).getFileAllName(),i);
                }
            }
        });
    }

    public void setOnAudioPlayerChangeListener(OnAudioPageChangeListener onAudioPageChangeListener) {
        this.mOnAudioPageChangeListener = onAudioPageChangeListener;
    }

    public void setCurAudioFileStatus(int index,boolean isPause){
        mAudioFileAdapter.setCurAudioFileStatus(index,isPause);
        mAudioFileAdapter.notifyDataSetChanged();
    }
    public void setAudioFileSelection(int index){
        mFileListView.setSelection(index);
    }
}
